package com.itheima.web.controller.oms;


import com.itheima.dto.oms.OrderReturnApplyDto;
import com.itheima.service.oms.IOmsOrderReturnApplyService;
import com.itheima.utils.ResultData;
import com.itheima.vo.oms.OmsOrderReturnApply;
import com.itheima.vo.oms.OrderReturnApplyVo;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 订单退货申请 前端控制器
 * </p>
 *
 * @author 王志斌
 * @since 2022-07-06
 */
@RestController
@RequestMapping("/returnApply")
public class OmsOrderReturnApplyController {
    @DubboReference
    private IOmsOrderReturnApplyService orderReturnApplyService;
    /**
     * 分页查询退货申请
     *
     * @param dto
     * @return
     */
    @GetMapping("/list")
    public ResultData list(OrderReturnApplyDto dto) {
        /*orderReturnApplyService.pagelist(dto)*/
        return ResultData.ok("",orderReturnApplyService.pagelist(dto));
    }
    /**
     * 获取退货申请详情
     *
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public ResultData getOrderReturn(@PathVariable Integer id) {
        OrderReturnApplyVo vo = orderReturnApplyService.getOrderReturn(id);
        return ResultData.ok("",vo);
    }
    /**
     * 修改退货申请状态
     *
     * @param id
     * @param orderReturnApply
     * @return
     */
    @PostMapping("/update/status/{id}")
    public ResultData updateStatus(@PathVariable Integer id, @RequestBody OmsOrderReturnApply orderReturnApply) {
        Integer count = orderReturnApplyService.updateStatus(id, orderReturnApply);
        if (count == null) {
            return ResultData.error("修改失败");
        }
        return ResultData.ok("修改成功","");
    }

    /**
     * 批量删除退货申请
     *
     * @param ids
     * @return
     */
    @PostMapping("/delete")
    public ResultData delete(@RequestParam List<Long> ids) {
        Integer count = orderReturnApplyService.delete(ids);

        if (count == null) {
            return ResultData.error("修改失败");
        }
        return ResultData.ok("修改成功","");
    }
}
